<template>
	<view>
		<view class="tabr" :style="{top:headerTop}">
			<view :class="{on:typeClass=='valid'}" @tap="switchType('valid')">待使用({{couponValidList.length}})</view><view :class="{on:typeClass=='invalid'}"  @tap="switchType('invalid')">已使用</view>
			<view class="border" :class="typeClass"></view>
		</view>
		<view class="place" ></view>
		<view class="list">
			<!-- 优惠券列表 -->
			<view class="sub-list valid" :class="subState">
				<view class="tis" v-if="couponValidList.length==0">仅保留30天内记录哦~</view>
				<view class="row" v-for="(row,index) in couponValidList" :key="index" >
					<!-- content -->
					<view class="carrier" :class="[typeClass=='valid'?theIndex==index?'open':oldIndex==index?'close':'':'']" @touchstart="touchStart(index,$event)" @touchmove="touchMove(index,$event)" @touchend="touchEnd(index,$event)">
						<view class="left">
							<image :src="prop[0].imageurl" mode="aspectFit" class="p"></image>
						</view>
						<view class="center">
							<view class="title">
								{{row.title}}
							</view>
							<view class="term">
								{{row.function}}
							</view>
						</view>
						<view class="right">
							<view class="use">
								<navigator url="#">
								使用
								</navigator>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="sub-list invalid" :class="subState">
				<view class="tis" v-if="couponinvalidList.length==0">仅保留30天内记录哦~</view>
				<view class="row" v-for="(row,index) in couponinvalidList" :key="index" >
					<!-- content -->
					<view class="carrier" :class="[typeClass=='invalid'?theIndex==index?'open':oldIndex==index?'close':'':'']" @touchstart="touchStart(index,$event)" @touchmove="touchMove(index,$event)" @touchend="touchEnd(index,$event)">
						<view class="left">
							<image :src="prop[0].imageurl" mode="aspectFit" class="p"></image>
						</view>
						<view class="center">
							<view class="title">
								{{row.title}}
							</view>
							<view class="term">
								{{row.function}}
							</view>
						</view>
						
						<view class="right invalid">
							<view class="use">
								<navigator url="#">
								查看
								</navigator>
							</view>
						</view>
						
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>

	export default {
		data() {
			return {
				couponValidList:[
					{id:1,title:"切换座位",function:"方便你切换到一个空座位",ticket:"10"},
					{id:2,title:"切换座位",function:"方便你切换到一个空座位",ticket:"100"},
					{id:3,title:"切换座位",function:"方便你切换到一个空座位",ticket:"10"},
					{id:4,title:"切换座位",function:"方便你切换到一个空座位",ticket:"50"}
				],
				couponinvalidList:[
					{id:1,title:"切换座位",function:"方便你切换到一个空座位",ticket:"10"},
					{id:2,title:"切换座位",function:"方便你切换到一个空座位",ticket:"100"},
					{id:3,title:"切换座位",function:"方便你切换到一个空座位",ticket:"10"},
				],
				
				prop:[
					{
						index:"0",
						name:"切换座位",
						fee:"10积分",
						imageurl:"https://xinguan-parent2.oss-cn-hangzhou.aliyuncs.com/all/15-26-51.png"
					},
					{
						index:"1",
						name:"小纸条",
						fee:"10积分",
						imageurl:"https://xinguan-parent2.oss-cn-hangzhou.aliyuncs.com/all/15-27-11.png"
					},
					{
						index:"2",
						name:"秒选道具",
						fee:"280积分",
						imageurl:"https://xinguan-parent2.oss-cn-hangzhou.aliyuncs.com/all/15-27-15.png"
					},
					{
						index:"3",
						name:"解除黑名单",
						fee:"360积分",
						imageurl:"https://xinguan-parent2.oss-cn-hangzhou.aliyuncs.com/all/15-27-24.png"
					},
					{
						index:"4",
						name:"消除违规记录",
						fee:"100积分",
						imageurl:"https://xinguan-parent2.oss-cn-hangzhou.aliyuncs.com/all/15-27-20.png"
					},
					{
						index:"5",
						name:"推迟15分钟签到",
						fee:"50积分",
						imageurl:"https://xinguan-parent2.oss-cn-hangzhou.aliyuncs.com/all/15-27-33.png"
					}
				],
				
				headerTop:0,
				typeClass:'valid',
			}
		},
		onLoad() {
				let Timer = setInterval(()=>{
					let uniHead = document.getElementsByTagName('uni-page-head');
					if(uniHead.length>0){
						this.headerTop = uniHead[0].offsetHeight+'px';
						clearInterval(Timer);
					}
				},1);
		},
		methods: {
			switchType(type){
				if(this.typeClass==type){
					return ;
				}
				uni.pageScrollTo({
					scrollTop:0,
					duration:0
				})
				this.typeClass = type;
				this.subState = this.typeClass==''?'':'show'+type;
				setTimeout(()=>{
					this.oldIndex = null;
					this.theIndex = null;
					this.subState = this.typeClass=='valid'?'':this.subState;
				},200)
			},
		}
	}
</script>
<style lang="scss">
	view{
		display: flex;
		flex-wrap: wrap;
	}
	page{position: relative;background-color: #ffffff;}
	.hidden{
		display: none !important;
	}
	.place{
		width: 100%;
		height: 45upx;
	}
	.tabr{
		background-color: #fff;
		width: 94%;
		height: 95upx;
		padding: 0 3%;
		border-bottom: solid 1upx #dedede;
		position: fixed;
		top: 0;
		z-index: 10;
		view{
			width: 50%;
			height: 90upx;
			justify-content: center;
			align-items: center;
			font-size: 32upx;
			color: #000000;
		}
		.on{
			color: #000000;
			font-weight: 700;
		}
		.border{
			height: 2upx;
			background-color: #1a1eeb;
			transition: all .3s ease-out;
			&.invalid{
				transform: translate3d(100%,0,0);
			}
		}
		
	}
	.list{
		width: 100%;
		display: block;
		position: relative;
	}
	@keyframes showValid {
		0% {transform: translateX(-100%);}100% {transform: translateX(0);}
	}
	@keyframes showInvalid {
		0% {transform: translateX(0);}100% {transform: translateX(-100%);}
	}
	.sub-list{
		&.invalid{
			position: absolute;
			top: 0;
			left:100%;
			display: none;
		}
		&.showvalid{
			display: flex;
			animation: showValid 0.20s linear both;
		}
		&.showinvalid{
			display: flex;
			animation: showInvalid 0.20s linear both;
		}
		width: 100%;
		padding: 20upx 0 120upx 0;
		.tis{
			width: 100%;
			height: 250upx;
			justify-content: center;
			align-items: center;
			font-size: 30upx;
		}
		.row{
			width: 92%;
			height: 24vw; 
			margin: 20upx auto 10upx auto;
			border-radius: 8upx;
			align-items: center;
			position: relative;
			overflow: hidden;
			z-index: 4;
			border: 0;
			.carrier{
				@keyframes showMenu {
					0% {transform: translateX(0);}100% {transform: translateX(-28%);}
				}
				@keyframes closeMenu {
					0% {transform: translateX(-28%);}100% {transform: translateX(0);}
				}
				background-color: #fff;
				position: absolute;
				width: 100%;
				padding: 0 0;
				height: 70%;
				z-index: 3;
				flex-wrap: nowrap;
				.left{
					padding-left: 10px;
					padding-top: 5px;
					.p{
						height: 60px;
						width: 50px;
					}
				}
				.center{
					width: 100%;
					padding-left: 10px;
					.title{
						padding-top: 3vw;
						font-weight: 700;
						width: 90%;
						margin: 0 5%;
						font-size: 36upx;
					}
					.term{
						width: 90%;
						margin: 0 5%;
						font-size: 16upx;
						color: #999;
					}
					position: relative;
				}
				.right{
					flex-shrink: 0;
					width: 28%;
					color: #fff;
					padding-top: 25px;
					background-color: #ffffff;
					justify-content: center;
					.use{
						width: 45%;
						height: 65upx;
						justify-content: center;
						align-items: center;
						font-size: 30upx;
						font-weight: 700;
						background-color: #ffeaea;
						color: #ff5500;
						border-radius: 40upx;
						padding: 0 25upx;
					}
				}
			}
		}
	}
	
</style>
